
var cir1,cir2,cir3,cir4,ds1,ds2,ds3;


$(document).ready(function() {
	
	//var pathPts1 = [[300,350],[360,390],[430,375],[550,430],[550,500]];
	//var pathPts2 = [[100,200],[300,170],[600,220],[700,200]];
	var pathPts1 = [[150,170],[360,320],[450,220]];
	var pathPts2 = [[450,220],[450,20],[1100,20]];
	var pathPts3 = [[450,220],[1100,220]];
	var pathPts4 = [[450,220],[450,420],[1100,420]];
	var canvasID = "arrow_svg";
	var docSVG = $("#" + canvasID).svg();
	
	//document.getElementById(canvasID).getElementsByTagName("svg")[0].style.zIndex = 99;
	//document.getElementById(canvasID).getElementsByTagName("svg")[0].style.height = 500;
	//document.getElementById(canvasID).getElementsByTagName("svg")[0].style.width = 500;
	document.getElementById(canvasID).getElementsByTagName("svg")[0].setAttribute('height',500);
	document.getElementById(canvasID).getElementsByTagName("svg")[0].setAttribute('width',1200);
	//var circuitUID = 0;
	//var cir1 = new Circuit(canvasID,pathPts1,0);
	//var cir2 = new Circuit(canvasID,pathPts2,3);
	
	cir1 = new Circuit(canvasID,pathPts1,0,'large');
	cir2 = new Circuit(canvasID,pathPts2,1,'medium');
	cir3 = new Circuit(canvasID,pathPts3,2,'small');
	cir4 = new Circuit(canvasID,pathPts4,3,'large');
	
	//cir1.initCircuit();
	//cir2.initCircuit();
	
	cir1.initCircuit();
	cir2.initCircuit();
	cir3.initCircuit();
	cir4.initCircuit();
	
	
	ds1 = new DeviceSound(document.getElementById("appliance1"),'ds1Player','vacuumcleaner');
	ds2 = new DeviceSound(document.getElementById("appliance2"),'ds2Player','blowdryer');
	ds3 = new DeviceSound(document.getElementById("appliance3"),'ds3Player','dishwasher');
	
	ds1.turnOn();
	ds2.turnOn();
	ds3.turnOn();
	
	//var hand1 = cir1.getSwitchHandle();
	//var hand2 = cir2.getSwitchHandle();
	
	
	//alert(hand1);
	//alert(hand2);
	//cir1.svg.circle(hand1[0], hand1[1], 25, {fill: 'none', stroke: 'red', strokeWidth: 3});
	//cir2.svg.circle(hand2[0], hand2[1], 25, {fill: 'none', stroke: 'red', strokeWidth: 3});
	//docSVG.circ(Math.floor(hand1[0]),Math.floor(hand1[1]),50,{stroke:'red',stroke-width:'3'});
	//docSVG.destroy();
	//var svg = $('#' + canvasID).svg('get');
	
	
	/*$('#toggle').change(function() {
		if ($('#toggle').attr('checked')) {
			cir1.show();
			//cir2.show();
		}
		else
		{
			cir1.hide();
			//cir2.hide();
		}
	});*/
});



function switch1Toggle(bool)
	{
		cir1.setState(bool);
		if (!bool)
		{
			cir2.setState(false);
			cir3.setState(false);
			cir4.setState(false);
			ds1.turnOff();
			ds2.turnOff();
			ds3.turnOff();
		}
		else
		{
			if (cir2.on)
			{
				ds1.turnOn();
			}
			if (cir3.on)
			{
				ds2.turnOn();
			}
			if (cir4.on)
			{
				ds3.turnOn();
			}
		}
	}

	function switch2Toggle(bool)
	{
		cir2.setState(bool);
		if (bool)
		{
			ds1.turnOn();
		}
		else
		{
			ds1.turnOff();
		}
	}

	function switch3Toggle(bool)
	{
		cir3.setState(bool);
		if (bool)
		{
			ds2.turnOn();
		}
		else
		{
			ds2.turnOff();
		}
	}

	function switch4Toggle(bool)
	{
		cir4.setState(bool);
		if (bool)
		{
			ds3.turnOn();
		}
		else
		{
			ds3.turnOff();
		}
	}